Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more advanced xml writer. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

d3f3kt
Copy link

@d3f3kt d3f3kt commented Feb 29, 2020

This new xml writer provides 3 more functions which are essential to handle complex xml structures.

  1. It's now possible to provide attributes to the root element. Because this attributes are given as an additional constructor argument, i have created a new class to avoid bc breaks.

As an alternative, a factory could be used which would call a setter Method.

  1. Nested array can be handled now.
  2. XML attributes can be defined with a traling '@'.

Example:

$writer = new \Port\Xml\AdvancedXmlWriter(
    new \XMLWriter(), '/tmp/aaa.xml', 'rootElement',
    ['rootAttribute' => 'rootValue']
);

$xml = [
    'key1' => 'value1',
    '@attribute1' => 'attributeValue1',
    'collection' => [
        'foo' => 'bar',
    ],
];
<?xml version="1.0"?>
<rootElement rootAttribute="rootValue">
    <item attribute1="attributeValue1">
        <key1>value1</key1>
        <collection>
            <foo>bar</foo>
        </collection>
    </item>
</rootElement>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant